package sn_gm_report

import org.DataUtils

/**
 * OEE controller
 */
class DwsPerformanceController {

    def commonDataService
    def dynamicQueryService
    def exportFileService

    def index(Integer max) {
        def cellList = org.kdx.DataUtils.getCellList()
        def pageSizeList = org.kdx.DataUtils.getPageSizeList()

        [totalCount: 5, pageSize: 20, pageCurrent: 1, orderField: 'id', orderDirection: 'asc', pageSizeList: pageSizeList, cellList: cellList]
    }

    def Report_074() {

        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        if (params.export == 'xls') {
            params.startno = 1
            params.endno = 56800
        } else {
            params.startno = (pageSize * (pageCurrent - 1)) + 1
            params.endno = pageSize * pageCurrent
        }

        params.SYS_QUERY_NAME = 'Report_074'
        def Report_074List = dynamicQueryService.queryForList(params)
        println(Report_074List)
        def tableHeadList = []
        if (Report_074List.size() > 0) {
            tableHeadList = Report_074List[0].keySet()
        }
        params.SYS_QUERY_NAME = 'Report_075eqpList'
        def eqpList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'eqpType'
        def eqptypeList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'moduleList'
        def ModuleList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'Report_074Count'
        def totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

        if (params.export == 'xls') {
            def str = g.render(template: "${params.EXPORT_CONTENT_NAME}", model: [Report_074List: Report_074List, tableHeadList: tableHeadList])
            exportFileService.exportExcelbyWeb(response, "${params.SYS_QUERY_NAME}", str)
        } else {
            [pageSizeList : DataUtils.getPageSizeList(), pageSize: pageSize, startno: params.startno ?: '', endno: params.endno ?: '',
             ModuleList: ModuleList, tableHeadList: tableHeadList, Report_074List: Report_074List, equipmentId: params.equipmentId ?: '',
             eqpList: eqpList, eqptypeList: eqptypeList, module       : params.module ?: '', eqpType: params.eqpType ?: '',
             startTime: params.startTime ?: '', endTime: params.endTime ?: '', totalCount: totalCount]
        }
    }
}
